﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ConnectionFactory.cs" company="CodePlex">
//   Copyright © CodePlex 2012
// </copyright>
// <summary>
//   Defines the ConnectionFactory type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace DataFrameworkGenerator.Factories
{
    using System;
    using System.Data;
    using System.Data.OleDb;

    /// <summary>
    /// A factory to generate database connections.
    /// </summary>
    public class ConnectionFactory
    {
        /// <summary>
        /// Generates the connection.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="connectionString">The connection string.</param>
        /// <returns>A database connection</returns>
        public static IDbConnection GenerateConnection(DatabaseType type, string connectionString)
        {
            IDbConnection connection;

            switch (type)
            {
                case DatabaseType.Access2003:
                    connection = new OleDbConnection(connectionString);
                    break;
                case DatabaseType.Oracle:
                    connection = new OleDbConnection(connectionString);
                    break;
                case DatabaseType.MsSql:
                    connection = new OleDbConnection(connectionString);
                    break;
                default:
                    throw new NotImplementedException(string.Format("Connection not implemented for type {0} in ConnectionFactory.", type));
            }

            return connection;
        }
    }
}